// 初始化Client
var co = require('co');
var OSS = require('ali-oss');

var client = new OSS({
    region: 'oss-cn-hangzhou',
    accessKeyId: 'LTAIxRhcyfiOMYDv',
    accessKeySecret: 'dI4lELKjbvf1eP8WKePRFn4hQN5rKc'
});
var ali_oss = {
    bucket: 'topcoin',
    endPoint: 'oss-cn-hangzhou.aliyuncs.com'
}

exports.uploadToOss = function(key, localFilePath, successFn, errorFn){

	// 阿里云 上传文件 
    co(function* () {
        client.useBucket(ali_oss.bucket);
        var result = yield client.put(key, localFilePath);
        var imageSrc = 'https://topcoin.oss-cn-hangzhou.aliyuncs.com/' + result.name;

        successFn && successFn(imageSrc)

    }).catch(function (err) {

        errorFn && errorFn(JSON.stringify(err))
    });
}